﻿
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ProductManager_SnedPrdt : System.Web.UI.Page
{
    GoShopping.BLL.Orders.InvoiceBean invBean = new GoShopping.BLL.Orders.InvoiceBean();
    GoShopping.BLL.Orders.OrderBean ordBean = new GoShopping.BLL.Orders.OrderBean();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {
                hidOrderId.Value = Request.QueryString["ID"].ToString();
                InitialPage();
            }
        }
    }

    private void InitialPage()
    {
        GetGVPrdts(Convert.ToInt32(Request.QueryString["ID"]));
        GoShopping.Model.Order ord = ordBean.GetOneOrder(Convert.ToInt32(Request.QueryString["ID"]));
        lblSendCode.Text = "";
        lblOrderCode.Text = ord.OrderCode;
        lblSendDate.Text = DateTime.Now.ToString();
        lblIsInsure.Text = "暂时没有,需要加一个字段标识保价费用";
        lblReceAdd.Text = ord.Province + ord.City + ord.County + ord.DetailStreet;
        lblReceiver.Text = ord.UserName;
        lblSendFee.Text = ord.PostPrice.ToString();
        lblSendMan.Text = "需要一个得到管理员ID的接口";
        lblSendType.Text = ord.AcceptType.ToString();
    }
    void GetGVPrdts(int orderId)
    {
        gvOrderPrdts.DataSource = ordBean.GetOrderEachPrdct(orderId);
        gvOrderPrdts.DataBind();
    }
    protected void btnComplete_Click(object sender, EventArgs e)
    {
        //保存信息到发货表
        GoShopping.Model.Invoice invMode = new GoShopping.Model.Invoice();
        invMode.OrderID = hidOrderId.Value;
        invMode.ReceiveUserName = lblReceiver.Text;
        invMode.RecordPersonID = new GoShopping.BLL.ProductManagerBean().GetOneProductManagerByName(User.Identity.Name).ID;
        invMode.Remarks = txtComment.Text.Trim() ;
        invMode.ReveiveUserAddress = lblReceAdd.Text;
        invMode.SendDate = Convert.ToDateTime(lblSendDate.Text);
        invMode.Sender = txtSender.Text.Trim();
        invMode.SendFee = Convert.ToDecimal(lblSendFee.Text);
        invMode.SendType = lblSendType.Text;
        invBean.Insert(invMode);
        //更新状态 已发货,待签收
        ordBean.UpdateOrder(Convert.ToInt32(Request.QueryString["ID"]), GoShopping.Model.Enumerations.OrderStatusType.SendedWaitRecieve);
        //跳转到详细页面
        Response.Redirect("OrderDetail.aspx?ID=" + Request.QueryString["ID"]);
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("OrderDetail.aspx?ID=" + hidOrderId.Value);
        
    }
}
